package cn.wsalix.templet.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.SimpleEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @author jskyme 模板实体
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "TEMPLET_PAGE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false, exclude = { "templet", "templetPagePlace" })
public class TempletPage extends SimpleEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4173272473220310459L;
	private String pageCode;//
	@NotEmpty
	@Column(name = "TEMP_FILE", nullable = false, length = 255)
	private String fileName;//
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_TP_TEMP"), name = "TEMP_ID")
	private Templet templet;
	@Transient
	private Long templetId;
	/*
	 * @JsonIgnore
	 * 
	 * @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
	 * "templetPage") private List<TempletPlace> templetPlaces;
	 */

	@JsonIgnore
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "templetPage")
	private List<TempletPagePlace> templetPagePlace;
}
